#!/usr/bin/python3
# -*- coding: utf-8 -*-

import allure
from playwright.sync_api import Page, expect

from models.base_page import BasePage


class NATPage(BasePage):
    def __init__(self, page: Page):
        super().__init__(page)
        self.route = "nat"

    def check_nat_page_user_guide_element_to_be_visible(self):
        """检查使用指南元素是否可见"""
        with allure.step("检查NATPage:使用指南元素是否可见"):
            self.expect.to_be_visible(self.page.locator("#micro-nat-root").get_by_text("NAT 网关", exact=True))
            self.expect.to_be_visible(self.page.get_by_role("button", name=" 使用指南"))
            self.expect.to_be_visible(self.page.get_by_text("收起").first)
            self.expect.to_be_visible(self.page.locator(".qicon > use").first)
            self.expect.to_contain_text(self.page.locator("#micro-nat-root"),
                                        "NAT 网关 (Network Address Transmition Gateway) 是一个分布式的网络地址转换服务。 "
                                        "NAT 网关为 VPC 网络内的云服务器提供了复用公网 IP 的能力， "
                                        "支持 SNAT 和 DNAT 功能，使多个云服务器可以共享公网 IP 访问互联网或提供互联网服务。")
            self.expect.to_contain_text(self.page.locator("#micro-nat-root"),
                                        "为私有网络/云服务器添加 SNAT / DNAT，实现VPC中的云产品与 Internet 互相访问")
            self.expect.to_be_visible(self.page.get_by_text("帮助指引"))
            self.expect.to_be_visible(self.page.get_by_text("收起").nth(1))
            self.expect.to_be_visible(self.page.locator(".qicon > use").first)
            self.expect.to_be_visible(self.page.get_by_text("购买 NAT 网关"))
            self.expect.to_be_visible(self.page.get_by_text("在 NAT 网关上绑定公网 IP"))
            self.expect.to_be_visible(self.page.get_by_role("button", name="查看更多"))

    def check_nat_page_table_element_to_be_visible(self):
        """检查工具栏及table是否可见"""
        with allure.step("检查NATPage:工具栏及table是否可见"):
            self.expect.to_be_visible(self.page.locator(".table-title-bar"))
            self.expect.to_be_visible(self.page.get_by_role("button", name="创建"))
            self.expect.to_be_visible(self.page.get_by_role("button", name="更多操作"))
            self.expect.to_be_visible(self.page.get_by_text("标签").nth(1))
            self.expect.to_be_visible(self.page.get_by_placeholder("请输入 NAT 网关或 VPC 网络名称/ ID"))
            self.expect.to_be_visible(self.page.locator(".table-search-wrapper > button"))
            self.expect.to_be_visible(self.page.locator("#micro-nat-root #floating-ui-7").get_by_role("button"))
